


The Genetic Algorithm

by Bitenomnom



Series: Mathematical Proof [28]
Category: Sherlock (TV)
Genre: Asexual!Sherlock, Cuddling, Fluff, Friendship, Gen, M/M, Mathematics, Sherlock Experiments on John, first person POV, this can be read as one or more of: the slow beginnings of a relationship, two points of view
Language: English
Status: Completed
Published: 2012-10-26
Updated: 2012-10-26
Packaged: 2017-11-17 01:51:28
Rating: Not Rated
Warnings: Creator Chose Not To Use Archive Warnings
Chapters: 1
Words: 3,786
Publisher: archiveofourown.org
Story URL: https://archiveofourown.org/works/546328
Author URL: https://archiveofourown.org/users/Bitenomnom/pseuds/Bitenomnom
Summary: <blockquote class="userstuff">
              <p>Some problems defy the usage of cold, clean-cut linear logic. It is impossible to devise a way to take steps that ultimately lead exactly to an optimal answer.</p><p>Sherlock believes John Watson is one of those problems.</p>
            </blockquote>





	The Genetic Algorithm

**Author's Note:**

> Not nearly what the title actually sounds like, by the way.
> 
> I'm feeling the pressure from all the other drabbles I wrote this week, since people seemed to like them a lot, so I really hope this one doesn't disappoint too terribly much. My mind was in other places (I really want to be working on The Case of the Moebius Trip; I have, like, three -other- AUs that I wish I had time to write...and so on).
> 
> But, I hope some pleasant fluff won't go amiss. (That being said, I hope the characters aren't too poorly written. XD Ugh. I am so out of it right now.) You can view this as the beginning of a relationship, with your choice of one or both of "romantic"/"physical" on either or both characters' sides, or you can view it as a nice fluffy friendship story. Or, of course, both!

The “genetic algorithm” or “evolutionary computation” is one method used to solve optimization problems with nonlinear (and nonquadratic!) objective functions. (That is, say you wanted to find out what variables get you the highest or lowest possible value of an equation with some variables raised to the fourth power.) In this method, the values of the various parameters are called “genes.” Genes are represented using binary notation (for instance 0.5 becomes 0.1; 0.75 becomes 0.11) and connected to form a long bit string in a fixed order. Then, all of the “genes” are connected to form “chromosomes.” These represent candidate solutions to the problem—not necessarily the best ones, although the best one may be among them. Then, a population is a group of chromosomes. You might start out with a “population” of 100 different “chromosomes,” different combinations of values to solve the problem.

 

Then, you want to calculate the “goodness” of these chromosomes to determine whether they are a suitable solution. You use some sort of function to rate them. For instance, if you were looking for a minimum value, you’d choose a goodness function where chromosomes with smaller values have more “weight” than ones with larger values. From this distribution, you then select parents. Because of the goodness function, you have greater odds of picking one of the more ideal chromosomes (i.e. the ones with the low values are “bigger” so you have more of a chance of picking them out).

 

What we want is to have an optimal solution, but this is not necessarily present in any given population. So we want to change the population somehow, while still keeping some of the goodness. Parents are selected at random, but with a greater chance of selecting the “good” ones to pass on their “genes.” Parents can be changed in several different ways. One is mutation, where one randomly selects one bit and switches it from 0 to 1 or 1 to 0. (This can also be done with two or more bits.) Another is crossover. In crossovers, you pick two parents, cut the chromosomes in the same place, and switch the two chunks. (You could also cut in two places and switch out, say, the middle chunk—this is a two-bit crossover.) The third is realignment. This involves cutting up the chromosome and rearranging the pieces (possibly even placing pieces of it in reverse order).

 

A random switch is performed to select the parents and then decide which of the three changes will be performed on the chromosomes. A number of children equal to the number of parents is produced. Then, you want to improve the next “generation.” To do this, you calculate the goodness of your new (for example) 100 offpsring, and put it with the other 100 parents, and then select the best 100. You then have to choose the best conditions under which to stop: this may be a maximum number of generations, it may be a case where every member of the population is more or less the same, or it may be a check for whether the best individual has been improved from generation to generation. (Likely, it is a combination of all of these.) Finally, after selecting the best individual, you decode the output to determine the values of the variables. Since this is a global search (see [The Merits of Local Searching](http://archiveofourown.org/works/540681)), there is no risk of falling into a small valley and never actually finding the region of the optimal answer. However, it is also time-consuming.

 

 

***  
  
            Some problems defy the usage of cold, clean-cut linear logic. It is impossible to devise a way to take steps that ultimately lead exactly to an optimal answer.

            I believe John Watson is one of those problems.       

            He would roll his eyes, of course, at that, believing that I mean to imply he is a _problem_ , when, in the way he means it, he is not. John is, by and large, the opposite of a problem. But that’s not what I mean: I mean something unsolved. That, too, is a problem. John is unsolved: he is a problem.

            It would appear, by my estimate, that a less elegant method is required. Something involving a bit more guessing, yes, but overall the end result is that progress will be made—precluding, of course, possibility of there being nothing _to_ conclude, but that seems highly unlikely.

            In particular, I intend to study the solution to the following question: what variables lead to the maximum amount of physical affection from John Hamish Watson?

 

 

 

            Sherlock is bloody doing it again.

            _It_ isn’t necessarily a particular thing, I suppose, but more like the sort of general nonsensical stuff that Sherlock _does_. Yesterday, he rearranged the sitting room. Today, the sitting room was put back just as the day before last, but the kitchen was rearranged. Yesterday, he cooked (yeah, I said cooked, I mean proper food, and not, I dunno, human fingers—at least, I hope not) lunch and dinner. Today, he cooked _breakfast_ and dinner and didn’t even want to acknowledge the fact that lunch had ever existed, let alone existed yesterday when he made it. (It’s _Sherlock,_ so he more or less just bought quick meals at the grocery, frozen dinners and so on, but it’s _Sherlock_ , so it counts.)

            Oh, right, and right now he’s marching through the room about every two minutes with a differently colored shirt on. He mumbles things like, “But you liked that blue painting, it must be blue,” and I honestly _don’t_ want to know what’s going through his head.

            Hopefully this is just one of those “bored” phases that’ll pass as soon as an interesting case crops up. God help me, I hope it’s soon.

 

 

 

            John gives me frustratingly little to go on. He seems to be generally against the arranging of furniture; he seems to be generally oblivious to whether my shirts bring out my eyes or my mouth or my fingernails; my reorganization of the refrigerator served to merely confuse rather than please him. I’ve hardly the spare time to think about the dull kidnapping case Lestrade brought in (not actually a kidnapping, for starters).

            So: rearranging: decidedly unhelpful. No marked change in levels of physical affection (reasonably low at present). Clothing: probably not worth the effort, but I shall continue to investigate—perhaps more extreme measures are necessary.

            Naturally, I must not survey the opinion of anyone else for this particular experiment; no one needs to know about this and they’d probably tell John, anyway, which would ruin the whole thing. They’d all be on about whether I’m going to kill him in his sleep (stupid; I could have done that a thousand times already), or whether I’ve got some sort of soft, gooey center (technically true; most internal organs are not known for their unyielding sturdiness). It’s not, to my knowledge, particularly unusual to crave affection, although I’m sure there would be much balking at thought of my bearing any similarity whatsoever to other humans. I didn’t really want it before, but there wasn’t John before. That part is simple: input John’s presence into my life, and the output is a general opinionatedness about whether John’s shoulder might be a not disagreeable resting place for my head.

            There are, I am sure, many more ways I could rearrange these variables. If I can find a handful of the most effective actions, I can proceed from there…

 

 

 

            Sod this.

            I mean it.

            Sod all of it.

            The lights in our flat don’t work.

            And it’s _not_ a power outage, in fact. Mrs. Hudson’s are fine. The lights in Sherlock’s room are fine. You know where the lights aren’t fine? Every-bloody-where else. The lights, the electricity in general.

            _I_ don’t know if Sherlock did it, and Mrs. Hudson doesn’t, either, but what I know is Sherlock is out and he isn’t answering his texts.

            Heaven forbid I, you know, want to use my laptop, or maybe eat some dinner _not_ in the darkness. Maybe I want to use the loo without tripping over a dressing gown that _somebody_ left on the floor.

            The only thing I really can do, of course, until I can figure out how to fix whatever Sherlock did (it has to have been him, hasn’t it?) to the lights, is get out some candles.

            Maybe he’s at least off working on that kidnapping case. Greg brought it in on Thursday and it took Sherlock to Saturday before he so much as lifted a finger on it. Those poor kids, trapped all the while. I’d have done it myself, and I even did take a look, but I hadn’t a single idea where to start. It doesn’t look anything like any of the kidnappings I’ve ever seen.

            And meanwhile, I suppose, while I figure out what I want to get for dinner (on Sherlock’s card, the git, for putting me through this), I can plug in my laptop in in Sherlock’s room.

            When he gets home, we are having a few words.

 

 

 

            I believe I have found some new data suggesting the direction in which I may proceed with some of the chosen variables.

            I took out the electricity in most of the rooms of 221B while I went to sort out all the details Lestrade got wrong in the case. “Off” and “on” are essential to binary functions; why not to functions in other aspects of life? The words are used frequently enough in common conversation (“turn-on,” “turn-off”).

            I came home to John eating takeaway on a candlelit table. He even got some for me, and although I’m certain he’s well aware that I generally don’t eat, I made an exception given his particular effort.

Candles induced by lack of electric lights are no less pleasant than candles lit for any other reason. John’s features are stunning in candlelight; in particular, his eyes become an ambiguous warm color that scatters light off with what might be described by someone with more poetic inclinations as an essence of pure life. (Which is, of course, what John is. He glows, himself, at the right times—and they are the _right_ times; just when I need him to. Most shrink away at gunshots and murders; John is a lighthouse.)

            I think, although it may be due to bias on my part, that the candlelight had some impact on John as well. He seemed to stare with more intensity than usual. The particular fashion in which his tongue tends to dart out onto his lips when he’s thinking of saying something occurred with heightened frequency; he wished to delay his words, then—some words that he very much needed to say, apparently—to further extend the moment of quiet as we ate.

            The words, it turned out, were more or less along the lines of, as I should have expected, berating me for being so selfish (John assumes this is for an experiment but obviously has no idea that that experiment is him) and foolish. He told me quite clearly that he considered opening the refrigerator to let my thumbs go bad, but didn’t want to deal with the hassle and aftermath. (Obviously, this must be John’s way of saying that while he generally does not care for my materials, he does wish not to upset me—again, I see, progress.)

            I retired to my room early to find John’s laptop there, plugged in to charge. The sight had an unexpected effect on me, as rather than open it up and browse what John had been doing I desired merely to look about it and consider its presence in my room. Something of John’s, simply occupying the space as if it belonged there—it should have bothered me, but it didn’t. It was from there that I selected which portions of this latest attempt should be carried over into the next.

            Later, John came in to retrieve his laptop. Another opportunity, obviously.

            “Put it in here to charge,” he clarified. His voice, I recall, was quiet, a bit rough—as if he had to keep his volume low despite the fact that I was clearly not asleep.

            “I know,” was what I said to him as he leaned down to unplug it. John and his laptop, in my bedroom, for all the world like they belonged there. I had to keep it for just a moment longer. “I’m…sorry,” I said. This tends to trip John up. He never expects it (nor should he).

            “Oh,” John said—or breathed more like. He wrapped the cable up and tucked his laptop under his arm. “Right, uh, well. Don’t do it again.”

            “I won’t.” Probably not, unless some other experiment calls for it, but no reason to bring up that stipulation before it’s necessary. John straightens up and hesitates—he knows he ought to leave, but he, too, is thinking of saying something else. Perhaps if I allow him an excuse to remain there, paused just by the corner of my bed. “Your solution to use candles was pleasant, nonetheless.” Something else, something else. “Perhaps I should test the possibility that candlelight increases my general interest in eating.”

            This caused John to laugh, apparently. “You really did eat, didn’t you? I was just going to save yours for myself.”

            “Well, I appreciate your having gone to the effort all the same.”

            This, apparently, threw John for a loop, as he licked his lips several more times. Perhaps it was a touch too maudlin. (Also, of course, a factor in the affection problem.) “Yeah, well,” he said, “I paid for it with your card.” Ah: compensating for my foolish, soft statements with something a little sharper. John—I thought, I still think—John, John, you are lovely.

            “Suppose I deserve it.”

            John smirked at that.

            “Before you leave, may I use your laptop to send an email?”  
            “Asking my permission and everything,” John said, handing it over. “I see you’re feeling gentlemanly this evening.”

            For John, of course, I would be more gentlemanly than I would for anyone else—not that that is saying a great deal, of course, as anyone would tell you, and myself most of all—but, I think, that is not what John wants. As I took the laptop from John’s hand, our fingers brushed.

            “You may as well sit,” I said. “It will be a minute.”

            John doesn’t mind standing—he generally prefers it. But this time he sat down, on the edge of the bed, certainly more than an arm’s reach away, but nonetheless there, on the bed. John has a manner of sitting that few others have: when he wishes it, he can remain perfectly still. His back is ramrod straight and his eyes are sharp.

            “I always thought your room was much too neat for a bloke like you,” John said while I was typing.

            “Oh?”

            “Everything else in the flat is a mess, but not here.”

            “Yes,” I rolled my eyes at him, “like some sort of untouched virgin land in the vast chaotic realms of 221B, isn’t it?”

            “Something like that,” John said back to me, although his mind was clearly elsewhere.

            “Don’t worry,” I said, hoping to assuage his concern, “your laptop is perfectly welcome to clutter it up.”

            When John finally took his laptop back from me, our fingers brushed again. “I’ll leave you to your virgin land, then,” he said as he left, clearly in playful jest (a pleasant turn to his rather unenjoyable rant about my shutting the electricity off). He paused at the doorway, glanced around, and then left.

            And now, of course, it’s morning, and as John prepares to leave to do some sort of boring locum work, I have determined my next course of action. I must wait until John leaves—it requires access to his room.

 

 

 

            I do wonder, some days while I’m off at work, what Sherlock spends his time on while I’m gone—when he’s not on a case, of course. Doing experiments, doubtless, or research on the internet, or maybe playing his violin, or reading one of he books on our shelves. Maybe he wanders around his mind palace, with a lack of anything else to entertain him.

            I had wondered today, of course, if I’d come back to the lights off.

            Here’s the thing about that. I...it didn’t turn out so bad. I mean, mostly confusing, but I guess who is Sherlock Holmes if not a very confusing man? He was obviously mesmerized by the candles, though I guess I can’t blame him—I was too. I mean. The light was really—interesting—on his face. You think he looks otherworldly in broad daylight, you ought to see him at an improvised candlelit dinner. Not that that was—a candlelit dinner. It was candlelit, and it was a dinner, but, you know, out of necessity. And I got a bit used to it, and it would be fine if we have to do that again tonight.

            Of course, we didn’t—aren’t. No, because just turning off the electricity again would be too easy.

            Sometimes I wonder what Sherlock gets up to while I’m gone, but usually my first thought is not _switching our bloody beds_.

            Which, by the way, is exactly what he did today.

            I probably wouldn’t have even noticed until I went up to my room, except that there was a very small scratch on the wall that wasn’t there before, the exact same color as the finish on my bed. When I pointed it out, Sherlock beamed.

            “Okay,” at present I am in the middle of trying not to yell at him, “why the _hell_ did that seem like a good idea to you?”  
            “Rearranging, John,” Sherlock says, and also, “Permutation!”

            The thing is— “The thing is,” I say to him, “I actually rather like my bed.”

            “Fine, so sleep in it.”

            “You just wanted to switch rooms for the night? That’s an _awful_ lot of effort for—why? Is it some sort of—are the neighbors you can see out my window up to something?”

            “Nothing like that,” he says, and then looks like he might have wished he’d said that instead of whatever is actually on his mind. “I just,” and now, oh god, he’s admitting to something, confessing something, _please_ don’t let it be ‘there’s a dead body in my bed’ or ‘I needed to store some entrails in the less humid air of your room and monitor them at night,’ “liked having you in my room. So I thought you might…you know. Come in again.”

            “For my bed.”

            “Yes.”

            “And why is it you like having me in your room, besides to borrow my laptop?”

            He shrugs.

            “Answer me, Sherlock.” This is important.

            “Can you just come in?”

            And with him looking all—I dunno, downtrodden or—shy—like that, I can’t exactly say no. So I get up and walk over to his door, and he follows quietly behind me, and sure enough my bed’s there, oriented not in the way that Sherlock’s was, but in the exact way mine was in my room.

            “I thought it would be more comfortable to you like that,” Sherlock explains.

            I step through the door. “There. I’m in your room. What is it that you want, Sherlock? Why did you do this?”

 

 

 

            It figures, of course, that John Watson is the one type of problem that cannot be solved through actual problem-solving techniques; it figures that John Watson is the one problem who will ask you to state your solution to his face.

            Of _course_ John would prefer the direct approach. I’d just hoped—but—

            “John,” I say, “will you please hold my hand?”  
            This obviously confuses him. He does so anyway. One reason John is a superior assistant to me is that he will do things I ask of him that confuse him, provided they seem important to me and not terribly morally questionable to him. Our fingers thread together and I am filled with warmth that any general increase in body heat cannot explain.

            “Will you sit with me?” I ask. I lead him over to his bed and we both perch on the edge. I lean my head against his shoulder; he doesn’t move. It’s perfect.

            “Are you okay, Sherlock?” he asks me. Good John, fantastic John, always concerned, and, given the evidence he’s been presented with thus far, asking a perfectly reasonable question.

            “I am now,” I say. Stupid—maudlin. But true.

            “Huh,” he curls his arm up and runs his hand—the one that’s not still holding mine—through my hair. “Are you, uh…” he starts, and shifts a little.

            “I’m not propositioning you.”

            “Oh. Right. Good. Okay.” He takes a few deep breaths. “You just…wanted…to…”

            “Mm,” I say, and nod, because that’s all I can think about right now as a pleasant, hazy fuzz obscures the other, usually busier parts of my mind.

            “I didn’t think you’d be a fan of—you know, touching. In general.”

            “I’m not,” I say, “in general.” I also, in general, never get along with my flatmates. (I also, in general, can’t stand the extended presence of other humans.) John, I think, must see this, because he eases a little, and squeezes my hand.

            John leans his head slightly so that it rests against mine. “I didn’t know that you needed this,” he says. “You should have told me.”

            “I know,” I say.

            “How about,” he says, “after we eat dinner and take time for a little classic sci-fi appreciation, and after you do something obnoxious like play your violin after Mrs. Hudson’s bedtime whilst looking over my shoulder and correcting all the typos in my blog entry,” I can’t hold back a chuckle, “and then tonight, I’ll sleep in my bed, and you’ll sleep in your room.”

            “Those are the same place, John.”

            He seems to find this conclusion amusing, but I’m still not sure he realizes what he said. “I know,” he finally says. “So if you don’t try anything funny, I won’t try anything funny.”  
            Oh— _oh._ He _meant_ it. My brain is lights and colors; my blood is close to my skin; my heart stutters to the tune of every piece I’ve ever played at once and my throat feels rather odd so I blurt, “Could we try ‘spooning’? Does that count as funny?”

            “Hmm,” he considers it, or pretends to, anyway. “I suppose it could be arranged.” He squeezes my hand again. “But let’s get dinner first.”  
            “And then…?”

            He grins, chuckles. “And then we can spoon.”

            And that is precisely what we do.


End file.
